package run.siyuan.service;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import run.siyuan.mapper.CommissionSettlementMapper;
import run.siyuan.model.CommissionSettlement;
import run.siyuan.model.IdIncrEntity;

import java.util.List;

/**
 * 佣金账单服务
 *
 * @author jinjingsu
 * @date 2021/03/19
 */
@Service
@Slf4j
public class CommissionSettlementService extends ServiceImpl<CommissionSettlementMapper,CommissionSettlement> {


    /**
     * 更新账单
     *
     * @param commissionSettlementIds
     */
    public void updateCommissionSetlements(List<Long> commissionSettlementIds) {
        long current = DateUtil.current();
        this.update(
                Wrappers.lambdaUpdate(CommissionSettlement.class)
                        .set(CommissionSettlement::getEntryBalance, true)
                        .set(CommissionSettlement::getEntryBalanceTime,current)
                        .in(IdIncrEntity::getId, commissionSettlementIds)
        );
    }

}
